//! Validation system demonstration
//! 
//! This example shows how to use the validation and assertion system.

use ai_test_platform::{
    validation::{ValidationEngine, ValidationContext, assertions::*},
    models::{Value, ValueMap},
};
use serde_json::json;
use std::collections::HashMap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("=== AI Test Platform Validation Demo ===");
    
    // Create a validation engine
    let engine = ValidationEngine::new();
    println!("✓ Validation engine created");
    
    // Create sample response data
    let mut response_data = HashMap::new();
    response_data.insert("status_code".to_string(), json!(200));
    response_data.insert("headers".to_string(), json!({
        "content-type": "application/json",
        "content-length": "42"
    }));
    response_data.insert("body".to_string(), json!({
        "message": "Hello, World!",
        "data": {
            "user_id": 12345,
            "email": "user@example.com",
            "items": [1, 2, 3, 4, 5]
        }
    }));
    
    let context = ValidationContext::new(response_data, HashMap::new());
    println!("✓ Validation context created");
    
    // Test value access
    println!("\n=== Testing Value Access ===");
    
    if let Some(status) = context.get_response_value("status_code") {
        println!("Status code: {}", status);
    }
    
    if let Some(message) = context.get_response_value("body.message") {
        println!("Message: {}", message);
    }
    
    if let Some(user_id) = context.get_response_value("body.data.user_id") {
        println!("User ID: {}", user_id);
    }
    
    if let Some(items) = context.get_response_value("body.data.items") {
        println!("Items: {}", items);
    }
    
    // Test assertion builders
    println!("\n=== Testing Assertion Builders ===");
    
    // Test OK response assertion
    let ok_assertion = CommonAssertions::ok();
    let (validators, extractors) = ok_assertion.build();
    println!("OK assertion - Validators: {}, Extractors: {}", validators.len(), extractors.len());
    
    // Test authentication response assertion
    let auth_assertion = CommonAssertions::auth_response();
    let (validators, extractors) = auth_assertion.build();
    println!("Auth assertion - Validators: {}, Extractors: {}", validators.len(), extractors.len());
    
    // Test custom assertion
    let custom_assertion = AssertionBuilder::new()
        .status_code(200)
        .json_path_equals("body.message", json!("Hello, World!"))
        .json_path_length("body.data.items", 5)
        .extract_json_path("body.data.user_id", "user_id")
        .extract_json_path("body.data.email", "user_email");
    
    let (validators, extractors) = custom_assertion.build();
    println!("Custom assertion - Validators: {}, Extractors: {}", validators.len(), extractors.len());
    
    // Test error response assertion
    let error_assertion = CommonAssertions::error_response();
    let (validators, extractors) = error_assertion.build();
    println!("Error assertion - Validators: {}, Extractors: {}", validators.len(), extractors.len());
    
    // Test paginated response assertion
    let paginated_assertion = CommonAssertions::paginated_response();
    let (validators, extractors) = paginated_assertion.build();
    println!("Paginated assertion - Validators: {}, Extractors: {}", validators.len(), extractors.len());
    
    println!("\n=== Demo Completed Successfully ===");
    
    Ok(())
}
